﻿toggle = function (fsid)
{
    var div = $id("div_" + fsid);
    var lnkdscd = $id("lnkdscd__lov_" + fsid);
    var lnkedit = $id("lnkedit__lov_" + fsid);
    var display = "";
    
    if( div.style.display != "none" )
    {
        display = "none";
    }
    
    div.style.display = display;
    if(lnkdscd != null)
    {
        lnkdscd.style.display = display;
    }
    if(lnkedit != null)
    {
        lnkedit.style.display = display;
    }
    
    
}
DoClose = function(){
    
    if(confirm("Close event?"))
    {
        //var load = $id("load_"+companyId);
        // di sini kirim data perubahannya
        var input = getGuestData();
        //load.innerHTML = "<img src='" + LOADING.src + "' alt='' />"; 
        cbkClose_c.PerformCallback(input);
    }
   
}
DoSave = function(){
    
    if(confirm("Simpan status kehadiran?"))
    {
        //var load = $id("load");
        // di sini kirim data perubahannya
        //var input = getGuestData();
        //load.innerHTML = "<img src='" + LOADING.src + "' alt='' />"; 
        var hf = $id("hfSave");
        hf.InnerHTML = "SAVE";
        dgCustomerList_c.PerformCallback("SAVE");
    }
   
}
cbkClose_c_CallbackComplete = function(e){
    if( e.parameter.startsWith("CLOSE"))
    {
        location.reload(true);
    }
}

dgCustomerList_c_CallbackComplete = function(e)
{
    var hf = $id("hfSave");
    if(hf.InnerHTML == "SAVE")
    {
//        var checkall = $id("lnkCheckAll");
//        var uncheck = $id("lnkUncheckAll");
//        var btn = $id("btnSave");
//        btn.style.display = "none";
//        checkall.style.display = "none";
//        uncheck.style.display = "none";
    }
}

getGuestData = function()
{
    //alert(companyId);
    //var invId = $id("hf.invitationid");
    var inputs = $nm("txt");
    var output = "CLOSE" + DELIMITER;
    
    for( var i=0; i < inputs.length; i++ )
    {
        if( i > 0 )
        {
            output += DELIMITER;
        }
        
        var item = inputs[i];
        var lov = $id("lov_" + item.id);
        
        if( lov == null )
        {
            output += item.id + NEWLINE + item.value;
        }
        else
        {
            var lovh = $id("lovh_" + item.id);
            output += lov.value + NEWLINE + lovh.value + NEWLINE + item.value;        
        }
    }
    //alert(output);
    return output;
    
}
checkAll = function()
{
    dgCustomerList_c.SelectAllRowsOnPage();
}
uncheckAll = function()
{
    dgCustomerList_c.UnselectAllRowsOnPage();
}

DoSubmitReason = function(invID)
{
//ambil data
    var reason = $id("lovh_UFT.REASON").value;
    //alert(reason);
    if(confirm("Simpan alasan?"))
    {
        cbkConfirm_c.PerformCallback("SUBMIT" + DELIMITER + invID + DELIMITER + reason);        
    }
}
Reason = function()
{
    //do nothing
}
cbkConfirm_c_CallbackComplete = function(e)
{
    if( e.parameter.startsWith("REASON") )
    {
        var div = $id("popuplayer");
        div.innerHTML = e.result;    }
    else if( e.parameter.startsWith("SUBMIT"))
    {
        var div = $id("popuplayer");        div.innerHTML = "";        div.style.display = "none";
        dgCustomerList_c.PerformCallback("SAVE");
    }
    else if(e.parameter.startsWith("DIRECTGUEST"))
    {
        dgCustomerList_c.PerformCallback("REFRESH");
    }
}
DoReason = function(invId)
{
    var div = $id("popuplayer");    div.style.display = "block";    div.innerHTML = "<img src='" + LOADING.src + "' alt='' />";    renderFirst();        cbkConfirm_c.PerformCallback("REASON" + DELIMITER + invId);
}

closeReason = function()
{
    var div = $id("popuplayer");    div.innerHTML = "";    div.style.display = "none";
}

SelectCompany = function()
{
    //do nothing
}

addLastGuest = function()
{
    var compId = $id("lovh_UFT.DIRECTGUEST").value;
    //alert(compId);
    cbkConfirm_c.PerformCallback("DIRECTGUEST" + DELIMITER + compId);
}

InviteGuest = function(invitationId, companyId){
    var div = $id("popupGuest");    var hfInvID = $id("hfInvID");    var hfCompID = $id("hfCompID");    hfInvID.value = invitationId;    hfCompID.value = companyId;    div.style.display = "block";    dgGuest_c.PerformCallback("INIT" + DELIMITER + invitationId + DELIMITER + companyId);    dgGuestSelected_c.PerformCallback("INIT" + DELIMITER + invitationId + DELIMITER + companyId);}
DoCancelGuest = function()
{
    var div = $id("popupGuest");    var hfInvID = $id("hfInvID");    var hfCompID = $id("hfCompID");    hfInvID.value = "";    hfCompID.value = "";    div.style.display = "none";
    dgGuest_c.SetVisible(false);
    dgGuestSelected_c.SetVisible(false);
    dgCustomerList_c.PerformCallback("REFRESH");
}
DoSelectGuest = function()
{
    var hfInvID = $id("hfInvID");    var hfCompID = $id("hfCompID");    invitationId = hfInvID.value;    companyId = hfCompID.value;
    dgGuestSelected_c.PerformCallback("SELECT" + DELIMITER + invitationId + DELIMITER + companyId);
}
checkAllGuest = function()
{
    dgGuest_c.SelectAllRowsOnPage();
}
uncheckAllGuest = function()
{
    dgGuest_c.UnselectAllRowsOnPage();
}
dgGuest_c_CallbackComplete = function()
{
    dgGuest_c.SetVisible(true);
    dgGuestSelected_c.SetVisible(true);
}
dgGuestSelected_c_CallbackComplete = function()
{
    uncheckAll();
}